<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="x-body">
    <div class="layui-row">
        <div class="layui-col-md4">
            <!--<form method="post" action="">-->
            <form class="layui-form" id="form1">
                <input type="hidden" name="id" value="{$data.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red"></span>排序
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" value="{$data.icon_sort}" name="icon_sort" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>图标名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="icon_name" required="" lay-verify="required"
                               autocomplete="off" class="layui-input" value="{$data.icon_name}">
                    </div>
                </div>
                <div class="layui-form-item" id="img1">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>图标
                    </label>
                    <button type="button" class="layui-btn" id="image1">
                        <i class="layui-icon">&#xe67c;</i>选择图片
                    </button>
                    {if $data.icon_logo eq null}
                        <input class='shop_image' value="" name='icon_logo'type='hidden'>
                    {else/}
                        <img src="{$data.icon_logo}" style='float: right;height: 60px;' alt='...'>
                        <input class='shop_image' value="{$data.icon_logo}" name='icon_logo'type='hidden'>
                    {/if}

                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red"></span>跳转网址
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="icon_url" value="{$data.icon_url}" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                    </label>
                    <button class="layui-btn" lay-filter="add" lay-submit="">
                        保存
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">

    layui.use(['form', 'layer','upload','laydate'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
            ,upload = layui.upload
            ,laydate = layui.laydate;

        laydate.render({
            elem: '#starttime'
            ,type: 'datetime'
        });

        laydate.render({
            elem: '#endtime'
            ,type: 'datetime'
        });

        layui.use('layedit', function(){
            var layedit = layui.layedit;
            layedit.build('demo'); //建立编辑器
        });

        var uploadInst = upload.render({
            elem: '#image1' //绑定元素
            ,url: '{:url("Shopinformation/shopImage")}' //上传接口
            ,done: function(res){
                $('#img1').children("img").remove();
                $('#img1').children(".icon_logo").remove();
                $('#img1').append("<img src='"+res.url+"' style='float: right;height: 60px;' alt='...'>");
                $('#img1').append("<input class='shop_image' value='"+res.url+"'name='icon_logo'type='hidden'>");
            }
            ,error: function(){
                //请求异常回调
            }
        });

        // //监听提交
        form.on('submit(add)',function (data){
            console.log(data.field);
            $.post('{:url("Shopinformation/iconEditForm")}',data.field,function (res) {
                if(res.code==1){
                    layer.alert(res.msg, {icon: 6}, function () {
                        xadmin.close();
                        xadmin.father_reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:1,time:1000});
                }
            });
            return false;
        });
    });
</script>
</body>

</html>